package ljl.codetop300;

public class _50_pow {

  /**
   * n 可能是 0，负数，正数
   */
  static class test {

    public static void main(String[] args) {
      System.out.println(new test().myPow(2, -Integer.MAX_VALUE));
    }

    public double myPow(double x, int n) {
      if(x == 0.0f) return 0.0d;
      long b = n;
      double res = 1.0;
      if (b < 0) {
        x = 1 / x;
        b = -b;
      }
      while(b > 0) {
        if((b & 1) == 1) res *= x;
        x *= x;
        b >>= 1;
      }
      return res;
    }
  }
}
